package com.example.rlw.mvpplugintest.details;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.rlw.mvpplugintest.R;
import com.example.rlw.mvpplugintest.adapter.MyPagerAdapter;
import com.example.rlw.mvpplugintest.music.MusicFragment;
import com.example.rlw.mvpplugintest.mvp.MVPBaseActivity;
import com.example.rlw.mvpplugintest.mvp.MVPBaseFragment;
import com.example.rlw.mvpplugintest.news.NewsFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class DetailsActivity extends MVPBaseActivity<DetailsContract.View, DetailsPresenter> implements DetailsContract.View, RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener {

    @BindView(R.id.tv_title_title)
    TextView mTvTitleTitle;
    @BindView(R.id.fragment1)
    RadioButton mFragment1;
    @BindView(R.id.fragment2)
    RadioButton mFragment2;
    @BindView(R.id.radioGroup)
    RadioGroup mRadioGroup;
    @BindView(R.id.viewPage)
    ViewPager mViewPage;

    private List<MVPBaseFragment> mFragmentList;

    @Override
    protected int getLayoutId() {
        return R.layout.details_layout;
    }

    @Override
    protected void initView() {
        mTvTitleTitle.setText("测试Fragment页面");
    }

    @Override
    protected void initData(@Nullable Bundle savedInstanceState) {
        mFragmentList = new ArrayList<>();
        mFragmentList.add(new NewsFragment());
        mFragmentList.add(new MusicFragment());
        mViewPage.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), mFragmentList));
        mRadioGroup.setOnCheckedChangeListener(this);
        mViewPage.addOnPageChangeListener(this);
    }

    @Override
    protected void initNet() {

    }

    @OnClick(R.id.ll_title_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (i) {
            case R.id.fragment1:
                mFragment1.setChecked(true);
                mViewPage.setCurrentItem(0);
                break;
            case R.id.fragment2:
                mFragment2.setChecked(true);
                mViewPage.setCurrentItem(1);
                break;
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                mFragment1.setChecked(true);
                break;
            case 1:
                mFragment2.setChecked(true);
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
